﻿PopUpDialog = {
    LoadMessage: function (element, message) {
        $("#" + element).html(message);
    },
    LoadUrl: function (element, url) {
        BlockUI.BlockElementLoading(element, "Loading..", true, 5);
        $("#" + element).load(url, function (response, status, xhr) {
            if (status == "error") {
                var msg = "Sorry but ther was an error:";
                $("#" + element).html(msg + xhr.status + " " + xhr.statusText);
            }
            BlockUI.UnBlockElement(element);
        });
    },
    CloseDialog: function (triggerName) {
        $("#popUp-" + triggerName).dialog("close");
    },
    MessageDialog: function (title, width, height, isModal, message, triggerName) {
        var popUpId = "popUp-" + triggerName;
        var selector = "<div id='" + popUpId + "'></div>";

        var popUpDialog = $(selector).dialog({
            modal: isModal,
            autoOpen: true,
            resizable: false,
            width: width,
            height: height,
            title: title,
            open: function () { PopUpDialog.LoadMessage(popUpId, message); },
            close: function () {
                $(popUpDialog).dialog("destroy");
                $(popUpDialog).remove();
            }
        });
    },
    UrlDialog: function (title, width, height, isModal, url, triggerName) {
        PopUpDialog.UrlDialogCallback(title, width, height, isModal, url, triggerName, null);
    },

    UrlDialogCallback: function (title, width, height, isModal, url, triggerName, closingDelegate) {
        var popUpId = "popUp-" + triggerName;
        var selector = "<div id='" + popUpId + "'></div>";

        var popUpDialog = $(selector).dialog({
            modal: isModal,
            autoOpen: true,
            resizable: false,
            width: width,
            height: height,
            title: title,
            open: function () {
                PopUpDialog.LoadUrl(popUpId, url);

            },
            close: function () {
                $(popUpDialog).dialog("destroy");
                $(popUpDialog).remove();
                if (closingDelegate != null) {
                    closingDelegate();
                }
            }
        });
    }
}


